Skip to content

Conversation

@NicolasHug
Copy link
Contributor

@NicolasHug NicolasHug commented Oct 24, 2025

Closes #978

TL;DR:

  • With the new Beta CUDA interface, we took a hard dependency on libnvcuvid.so.
  • When installing our GPU wheels, import torchcodec now fails if libnvcuvid.so isn't available.
  • libnvcuvid.so isn't usually installed with the normal CUDA toolkit installations, so it's not rare for it not to be available. So, it's not rare for import torchcodec to fail. That's bad - it's my fault, I missed that.
  • In this PR, we now load libnvcuvid.so at runtime only when necessary (i.e. only when the user explicitly requests the beta backend). This makes import torchcodec work, like before. We fallback to the CPU interface if it's not available , that's what FFmpeg does too!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 24, 2025
@NicolasHug
Copy link
Contributor Author

Hey @traversaro, I saw you already opened #983 for this, thank you!!

We're getting more reports related to nvcuvid.so being missing and thus the import torchcodec crashing, so I want to bump the priority of this and potentially release a bug-fix release soon.

This is my current attempt, it seems to be working fine locally, let's see what the CI says. I'm only handling linux for now but Windows will come, if this works.

@traversaro
Copy link
Collaborator

Hey @traversaro, I saw you already opened #983 for this, thank you!!

Great, thanks for opening the PR. That was just an initial attempt I did not had time to follow up, so it is great if you can work on this, thanks!

@meta-codesync
Copy link

meta-codesync bot commented Oct 27, 2025

@NicolasHug has imported this pull request. If you are a Meta employee, you can view this in D85561942.

@NicolasHug
Copy link
Contributor Author

@traversaro is there any chance you could try to see if the current PR works fine on Windows GPUs? I've added the code to dynamically load the dll at runtime, but we don't have Windows GPU CI jobs, so I can't verify myself that it's working as intended

return true;
}
} // namespace facebook::torchcodec
#else
Copy link
Contributor Author

@NicolasHug NicolasHug Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm fbcode build and tests are fine with the above. Also, FBCODE_CAFFE2 is very public on pytorch's GH repo: https://github.com/search?q=repo%3Apytorch%2Fpytorch%20FBCODE_CAFFE2&type=code

@NicolasHug NicolasHug marked this pull request as ready for review October 27, 2025 13:27
else()
message(FATAL_ERROR "Could not find NVCUVID library")
endif()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing a bunch of cmake code removed makes me irrationally happy. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait until you see the dlopen() stuff 😅

Copy link
Contributor

@scotts scotts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, agreed this is worth a fixpack.

@NicolasHug
Copy link
Contributor Author

NicolasHug commented Oct 27, 2025

QQ @traversaro do you need this PR to be merged (and maybe released as a bugfix) to test it? IIRC in a previous comment you mentioned that testing the build was a lot easier for you on stable releases, so I just want to make sure

@traversaro
Copy link
Collaborator

QQ @traversaro do you need this PR to be merged (and maybe released as a bugfix) to test it? IIRC in a previous comment you mentioned that testing the build was a lot easier for you one stable releases, so I just want to make sure

I am testing it now with a local modified version of conda-forge/torchcodec-feedstock#38, I will report the results here. No need for a release for the tests.

@traversaro
Copy link
Collaborator

Just tested on Windows, the test pass fine and the GPU is used, so I guess we are good to go w.r.t. to that!

@NicolasHug
Copy link
Contributor Author

Great, thank you so much for testing! I'll push a bugfix release later this week

@NicolasHug NicolasHug merged commit 28cec51 into meta-pytorch:main Oct 27, 2025
62 checks passed
@NicolasHug NicolasHug deleted the dylink branch October 27, 2025 17:08
NicolasHug added a commit to NicolasHug/torchcodec that referenced this pull request Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamically load nvcuvid library?

3 participants